#include <stdio.h>
#include <stdlib.h>
#include <sys/select.h>
#include "wpa_ctrl.h"

int main()
{
	struct wpa_ctrl *ctrl = wpa_ctrl_open("/var/run/hostapd_wlan0_vap0/vap0");
	if (ctrl) {
		printf("sucess");
	}
	if (wpa_ctrl_attach(ctrl)) {
		printf("wpa_ctrl_attach\n");
		exit(0);
	}
	int fd = wpa_ctrl_get_fd(ctrl);
	printf("sel fd = %d\n", fd);
	fd_set rset, oset;
	FD_ZERO(&rset);
	FD_SET(fd, &rset);

	char buf[4096];
	size_t len = sizeof(buf);
	int pos = 0;
	while (1) {
		oset = rset;
		select(fd + 1, &oset, NULL, NULL, NULL);
		if (wpa_ctrl_pending(ctrl)) {
			len = sizeof(buf);
			wpa_ctrl_recv(ctrl, buf, &len);
			buf[len] = 0;
			printf("\033[1;31m debug info = %s\033[0m\n", buf);
		}
	}
	return 0;
}